home *** CD-ROM | disk | FTP | other *** search
- #include <clib/all_protos.h>
- #include <exec/types.h>
- #include <math.h>
- #include <float.h>
-
- extern void PlotIt(UWORD);
- extern double Limit,XCenter,Factor,Two,PowerN,Pi,PiD2,TwoPi,DX;
- extern double PowerF;
- extern SHORT Power;
- extern UWORD Color;
- extern LONG xtemp,MaxCnt,RightEdge;
- extern ULONG *ColorTable32,*LPixelBuf;
- extern int BPP;
-
- double ReduceTheta(double);
-
- double GetTheta(double,double);
-
- double GetTheta(double xVal,double yVal)
- {
- double Ratio,Theta;
- Ratio = yVal/xVal;
- if (Ratio*Ratio <= 1.0e4) {
- Theta = atan(Ratio);
- if (xVal < 0.) Theta = Theta + Pi;
- if (Theta < 0.) Theta = Theta + TwoPi;
- return(Theta);
- }
- else {
- Theta = PiD2 - atan2(xVal,yVal);
- if (Theta < 0.) Theta = Theta + TwoPi;
- return(Theta);
- }
- }
-
- double ReduceTheta(double Theta)
- {
- while (Theta > TwoPi) Theta = Theta - TwoPi;
- return(Theta);
- }
-
- /* Note that GetRadN is faster than using PowerN*log(Zr) */
- double GetRadN(double Zr)
- {
- double RadN,RadM;
- int Cnt;
- RadM = Zr;
- for (Cnt=1;Cnt<Power;Cnt++) RadM = RadM*Zr;
- RadN = PowerF*log(Zr);
- RadN = exp(RadN);
- RadN = RadM*RadN;
- return(RadN);
- }
-
- void FncFnd(double yRelL)
- {
- double xRel,yRel,Rad2,Rad,Theta,ThetaN,RadN,Rad2N,Zr,Za,Zr2;
- ULONG *ColSrc;
- int CurCnt;
- yRel = yRelL;
- xtemp = 0;
- while (xtemp < RightEdge) {
- xRel = (double)xtemp - XCenter;
- xRel = xRel/Factor;
-
- yRelL = yRel;
- Rad2 = xRel*xRel + yRelL*yRelL;
- Theta = GetTheta(xRel,yRelL);
- Rad = sqrt(Rad2);
-
- CurCnt = 1;
- Zr = Rad;
- Za = Theta;
- Zr2 = Zr*Zr;
- while (CurCnt < MaxCnt) {
- if (Zr2 > Limit) {
- Color = CurCnt;
- goto Finish;
- }
- if (Zr) {
- RadN = GetRadN(Zr);
- Rad2N = RadN*RadN;
- }
- else {
- Color = 0xffff;
- goto Finish;
- }
- ThetaN = PowerN*Za - Theta;
- Zr2 = Rad2 + Rad2N + Two*Rad*RadN*cos(ThetaN);
- Zr = sqrt(Zr2);
- yRelL = RadN*sin(ThetaN);
- xRel = Rad + RadN*cos(ThetaN);
- Za = Theta + GetTheta(xRel,yRelL);
- CurCnt++;
- }
- Color = 0xffff;
- Finish:
- if (BPP < 2) PlotIt(Color);
- else {
- ColSrc = (ULONG *)ColorTable32 + (ULONG)Color;
- *LPixelBuf++ = *ColSrc;
- }
- xtemp++;
- }
- }
-